﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Data;

namespace EducationManagementSystem.Zr
{
    public partial class ZR : System.Web.UI.MasterPage
    {
        string zrpwd = "";
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Session["zname"] != null)
            {
                Label1.Text = "欢迎----" + Session["zname"].ToString() + "----主任进入系统";

            }
        }

        protected void LinkButton1_Click(object sender, EventArgs e)
        {
            SqlConnection conn = DB.Conn();
            conn.Open();
            if (TextBox1.Text == "" || TextBox2.Text == "")
            {
                this.Page.RegisterStartupScript(" ", "<script>alert('修改不能为空密码'); </script> ");
            }
            else if (TextBox1.Text != TextBox2.Text)
            {
                this.Page.RegisterStartupScript(" ", "<script>alert('确认密码不一致'); </script> ");
                TextBox2.Text = "";
            }
            else
            {
                SqlConnection conn1 = DB.Conn();
                conn1.Open();
                string sql1 = "update zhuren set zhurenpwd='" + TextBox2.Text + "' where zhurenid='zr001' ";
                SqlCommand cmd1 = new SqlCommand(sql1, conn);

                int a = cmd1.ExecuteNonQuery();
                if (a > 0)
                {
                    this.Page.RegisterStartupScript(" ", "<script>alert('密码修改成功，为确保用户信息安全，注销重新登录'); </script> ");

                }
                else
                {

                    this.Page.RegisterStartupScript(" ", "<script>alert(' 对不起，密码修改失败，服务器正在维护 '); </script> ");
                }
            }
        }

        protected void LinkButton2_Click(object sender, EventArgs e)
        {
            Session.Remove("zname");
            Response.Write("<script>parent.window.location.href='../login.aspx'</script>");
        }
        /// <summary>
        /// 原密码
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void TextBox3_TextChanged(object sender, EventArgs e)
        {
            SqlConnection conn = DB.Conn();
            conn.Open();
            string sql = "select zhurenpwd from zhuren where zhurenid='zr001' ";
            SqlCommand cmd = new SqlCommand(sql, conn);
            DataSet ds = new DataSet();
            SqlDataAdapter sda = new SqlDataAdapter(cmd);
            sda.Fill(ds);
            zrpwd = ds.Tables[0].Rows[0][0].ToString();
            if (TextBox3.Text != zrpwd)
            {
                this.Page.RegisterStartupScript(" ", "<script>alert('原密码输入错误'); </script> ");
                TextBox3.Text = "";
            }
            else
            {

                this.Page.RegisterStartupScript(" ", "<script>alert('原密码输入正确'); </script> ");
                TextBox1.Enabled = true;
                TextBox2.Enabled = true;
                //TextBox3.Text = stupwd;这样是没有办法赋值的,没有value存储
                this.TextBox3.Attributes["value"] = zrpwd;

                TextBox3.Enabled = false;
            }
        }
    }
}